package com.db;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

public class HelloEM {

	EntityTransaction tx;

	EntityManagerFactory emf;

	EntityManager em;

	public HelloEM() {
		emf = Persistence.createEntityManagerFactory("demojpa-pu");

		em = emf.createEntityManager();

		tx = em.getTransaction();

		tx.begin();

	}

	public void test() {

		em.persist( new Formation("Hibernate"));
		em.persist( new Formation("Test"));

		tx.commit();

		
	}
	
	public void close()
	{
		em.close();
		emf.close();
	}

	public EntityTransaction getTx() {
		return tx;
	}

	public void setTx(EntityTransaction tx) {
		this.tx = tx;
	}

	public EntityManagerFactory getEmf() {
		return emf;
	}

	public void setEmf(EntityManagerFactory emf) {
		this.emf = emf;
	}

	public EntityManager getEm() {
		return em;
	}

	public void setEm(EntityManager em) {
		this.em = em;
	}

}
